package com.zz.yt.lib.bluetooth.utils;



import androidx.annotation.NonNull;


/**
 * 蓝牙de温度转换工具
 *
 * @author qf
 * @version 1.0
 **/
public final class TemperatureUtil {

    private final static char[] HEX_CHAR_TABLE = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70};


    @NonNull
    public static String getHexString(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
        StringBuilder localStringBuffer = new StringBuilder();
        int j = paramInt1;
        for (; ; ) {
            if (j >= paramInt1 + paramInt2) {
                return localStringBuffer.toString();
            }
            int k = paramArrayOfByte[j] & 0xFF;
            localStringBuffer.append(HEX_CHAR_TABLE[(k >>> 4)]);
            localStringBuffer.append(HEX_CHAR_TABLE[(k & 0xF)]);
            localStringBuffer.append(" ");
            j += 1;
        }
    }

    /**
     * 获取温度值
     *
     * @param hexString:
     * @return s
     */
    @NonNull
    public static String getResultTemperature(String hexString) {
        try {
            String[] split = hexString.split(" ");
            int tmpInt = Integer.parseInt(split[1] + split[2], 16);
            return (tmpInt * 0.1f + "").substring(0, 4);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
}